import { Component, OnChanges,OnInit, SimpleChanges, Input } from '@angular/core';
import { HttpServcie } from '../../../service/http.service';
import { Router } from '@angular/router';
import { NzNotificationService } from 'ng-zorro-antd';
import { Observable } from 'rxjs/Observable';

@Component({
    selector: 'superviser-party',
    templateUrl: 'superviser-party.html',
    styleUrls: ['superviser-party.scss']
})

export class SuperviserParty implements OnInit,OnChanges {

    constructor(
        private httpServcie: HttpServcie,
        private router: Router,
        private _notification: NzNotificationService
    ) { 

    }
    @Input() partyId: string="";
   
    elevatorTotal;string;
    numlist=[];
    elevatorTypeData=[];

    usedPartyNum :any;
    maintPartyNum :any;
    feebbackRio: any;
    option1 = {};
    option2 = {};
    option4 = {};
    option5 = {};
    jianguanll=[];
    rescueNum:any;
    drillNum:any;
    checkOrgCount:any;
    repairRio:any;
    czryNumTotal:any;
    maintInRio:any;

    totalMember:number=0;
    cztotalMember:number=0;

    ngOnInit() {
        //Called after the constructor, initializing input properties, and the first call to ngOnChanges.
        //Add 'implements OnInit' to the class.
        
    }

    ngOnChanges(changes: SimpleChanges) {


        this.countCompanyQuali();
        this.countUserNum();

    }

    //查询机构人员数量
    countUserNum(){
        let param={
            id: this.partyId
        }
        this.httpServcie.countUserNum(param).subscribe(data => {
            if(data.data && data.data.length>0){
                let memberList = [];
                let nameList = [];
                data.data.forEach(element => {
                    
                    if(element.id!=this.partyId){
                        memberList.push({
                            name:element.party_name,
                            value:element.user_num
                        })
                        nameList.push(element.party_name);
                    }else{
                        this.totalMember =element.user_num;
                    }
                    
                });

                this.option1 = {
                    title : {
                        text: '下级单位人员数量',
                        subtext: '',
                        x:'center'
                    },
                    tooltip : {
                        trigger: 'item',
                        formatter: "{a} <br/>{b} : {c} ({d}%)"
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left',
                        data: nameList
                    },
                    series : [
                        {
                            name: '数量',
                            type: 'pie',
                            radius : '30%',
                            center: ['45%', '50%'],
                            data:memberList,
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };
            }
        });
    }

    //查询机构持证人员数量
    countCompanyQuali(){
        let param={
            id: this.partyId
        }
        this.httpServcie.countCompanyQuali(param).subscribe(data => {
            if(data.status==200){
                let jianguanList = data.data;
                let memberList = [];
                let nameList = [];
                jianguanList.forEach(element => {
                    
                    if(element.id!=this.partyId){
                        memberList.push({
                            name:element.party_name,
                            value:element.holders_num
                        })
                        nameList.push(element.party_name);
                        this.cztotalMember +=element.holders_num*1;
                    }else{
                        this.cztotalMember +=element.holders_num*1;
                    }
                    
                });
               

                this.option2 = {
                    title : {
                        text: '下级单位持证人员数量',
                        subtext: '',
                        x:'center'
                    },
                    tooltip : {
                        trigger: 'item',
                        formatter: "{a} <br/>{b} : {c} ({d}%)"
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left',
                        data: nameList
                    },
                    series : [
                        {
                            name: '数量',
                            type: 'pie',
                            radius : '30%',
                            center: ['45%', '50%'],
                            data:memberList,
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };

            } else if (data.status === 401) {
                this.router.navigateByUrl('/login');
                return;
              } else {
                // 异常
                this._notification.create('error', '错误提示', data.message);
              }
        })
    }

}
